//
//  ZNChatController.m
//  ZNChatDemo
//
//  Created by Sniper on 16/3/18.
//  Copyright © 2016年 Sniper_Personal. All rights reserved.
//

#import "ZNChatController.h"
#import "ZNChatToolView.h"
#import "ZNChatCell.h"

@interface ZNChatController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *chatTblView;
@property (weak, nonatomic) IBOutlet ZNChatToolView *chatToolView;
/** 数组 */
@property (nonatomic, strong)NSMutableArray *chatList;

@end

@implementation ZNChatController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.chatTblView.dataSource = self;
    self.chatTblView.delegate = self;
    self.chatTblView.backgroundColor = [UIColor lightGrayColor];
    
    self.chatList = [NSMutableArray array];
    
    ZNMessage *message1 = [[ZNMessage alloc] init];
    message1.headImgUrl = @"myHead";
    message1.messageContent = @"你好啊, 约吗? 走一杯啊";
    message1.fromWho = ZNMessageSenderTypeFromMe;
    
    ZNMessage *message2 = [[ZNMessage alloc] init];
    message2.headImgUrl = @"urHead";
    message2.messageContent = @"好啊";
    message2.fromWho = ZNMessageSenderTypeFromYou;
    
    ZNMessage *message3 = [[ZNMessage alloc] init];
    message3.headImgUrl = @"myHead";
    message3.messageContent = @"在哪约?";
    message3.fromWho = ZNMessageSenderTypeFromMe;
    
    ZNMessage *message4 = [[ZNMessage alloc] init];
    message4.headImgUrl = @"urHead";
    message4.messageContent = @"你知道哪里有卖东北那种大串的不? 鲁着贼爽那种,最好再配个扎啤";
    message4.fromWho = ZNMessageSenderTypeFromYou;
    
    ZNMessage *message5 = [[ZNMessage alloc] init];
    message5.headImgUrl = @"myHead";
    message5.messageContent = @"必须知道啊,就搁内疙瘩, 行动地铁站那边就有一家,两块钱一串 老劲老high了,是LBT 整点啊？";
    message5.fromWho = ZNMessageSenderTypeFromMe;
    
    ZNMessage *message6 = [[ZNMessage alloc] init];
    message6.headImgUrl = @"myHead";
    message6.messageContent = @"LBT就是路边摊";
    message6.fromWho = ZNMessageSenderTypeFromMe;
    
    ZNMessage *message7 = [[ZNMessage alloc] init];
    message7.headImgUrl = @"myHead";
    message7.messageContent = @"ok 到时候见吧那就";
    message7.fromWho = ZNMessageSenderTypeFromYou;
    
    [self.chatList addObject:message1];
    [self.chatList addObject:message2];
    [self.chatList addObject:message3];
    [self.chatList addObject:message4];
    [self.chatList addObject:message5];
    [self.chatList addObject:message6];
    [self.chatList addObject:message7];
    
    [self.chatTblView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.chatList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZNChatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"123"];
    if (!cell) {
        cell = [ZNChatCell chatCell];
    }
    ZNMessage *message = [self.chatList objectAtIndex:indexPath.row];
    cell.message = message;
//    NSLog(@"cellforrow cellheight : %.2f", message.cellHeight);
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZNMessage *message = [self.chatList objectAtIndex:indexPath.row];
    NSLog(@"heightForRow cellheight : %.2f", message.cellHeight);
    return message.cellHeight;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 240;
}

@end
